﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command;
using B.S.DataBase.MyWrite.API.Appicant.Command.Users;
using MediatR;

namespace B.S.DataBase.MyWrite.API.Appicant.CommandHandler.Users
{
    public class FanTianUserCommandHandler : IRequestHandler<FanTianUserCommand, APIResult<List<User>>>
    {
        private readonly IBaseRepository<User> userRep;
        public FanTianUserCommandHandler(IBaseRepository<User> userRep)
        {
            this.userRep = userRep;
        }
        public async Task<APIResult<List<User>>> Handle(FanTianUserCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<User>> result = new APIResult<List<User>>();
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();

            var list = userRep.GetAll().Where(x=>x.UserId==request.UserId);
            result.data=list.ToList();
            return await Task.FromResult(result);
        }
    }
}
